# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Drew DeVault <sir@cmpwn.com>
pkgname=shiboken2
pkgver=5.15.2
pkgrel=7
pkgdesc="CPython bindings generator for C++ libraries"
url="https://wiki.qt.io/Qt_for_Python/Shiboken"
arch="all !armhf" # qt5-qtxmlpatterns -> qt5-qtdeclarative
license="GPL-2.0-or-later"
depends_dev="python3-dev"
makedepends="
	cmake
	$depends_dev
	qt5-qtbase-dev
	qt5-qtxmlpatterns-dev
	clang-dev
	libxml2-dev
	libxslt-dev
	py3-numpy-dev
	py3-setuptools
	samurai
	"
subpackages="lib$pkgname:libs lib$pkgname-dev py3-$pkgname:py3"
source="https://download.qt.io/official_releases/QtForPython/pyside2/PySide2-$pkgver-src/pyside-setup-opensource-src-$pkgver.tar.xz
	python-3.10.patch
	"
builddir="$srcdir/pyside-setup-opensource-src-$pkgver"

provides="shiboken=$pkgver-r$pkgrel" # For backward compatibility
replaces="shiboken" # For backward compatibility

build() {

	export CLANG_INSTALL_DIR=/usr
	cmake -B "$builddir"/build sources/shiboken2 \
		-G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_TESTS=OFF \
		-DUSE_PYTHON_VERSION=3
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

libs() {
	license="LGPL-2.1-or-later"
	default_libs
}

dev() {
	license="LGPL-2.1-or-later"
	default_dev
	provides="shiboken-dev=$pkgver-r$pkgrel"
	replaces="shiboken-dev"
}

py3() {
	license="LGPL-2.1-or-later"
	depends=""
	pkgdesc="Python3 shiboken bindings"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/python3* "$subpkgdir"/usr/lib
	provides="py3-shiboken=$pkgver-r$pkgrel" # For backward compatibility
	replaces="py3-shiboken" # For backward compatibility

	# Install egg info
	cd "$builddir"
	export PATH="/usr/lib/qt5/bin:$PATH"
	python3 setup.py egg_info --build-type=shiboken2
	pythonpath="$(python3 -c "from sysconfig import get_path; print(get_path('platlib'))")"
	cp -r shiboken2.egg-info "$subpkgdir/$pythonpath"
}

sha512sums="
5043c1c9db4ba0133baaabb4d4943182e9741b1007bedd992394758707a37bba0688dc6413ea46620e7c2fb09daa3c74e6a7bb2c302b9d08e5f3bb7575d02b62  pyside-setup-opensource-src-5.15.2.tar.xz
a7e37bc1148b4df37b37fd5747f2e6596a5bf554369a63187bff193c66e2caba1719821ffb69ce5d647efd7aa73c8047607970239b07eea6a4814e924b4c3d4c  python-3.10.patch
"
